<?php 
class queryuser extends MsssqlDB 
{
	public function __construct()
	{
		 parent::__construct("mssql.infratechastm.com","infratechastm_dede","system1","infratechastm_Mockup");
	}
	
	public function setroledata()
	{
		return $this->msssqlselectdata("*",'[dbo].[Roles]',"");
	}
	
	public function adduser($names,$lastname,$mails,$tel,$workp,$useradd,$passadd,$passcon,$pz)
	{	
		if(!empty($names) and !empty($lastname) and !empty($mails) and !empty($tel) and !empty($workp)
		and !empty($useradd) and !empty($passadd) and !empty($passcon)and !empty($pz)){
		
				if($passadd == $passcon){
				
					$chnames = $useradd;
					
						$input = "'$names','$lastname','$mails','$tel','$workp','$useradd','$passadd','$pz','2'";
						
						$checknames = $this->mysqlnumrow($this->selectdatasql("*","usersystem","usernamelogin = '$chnames'"));
					
							if($checknames == 0 ){
								
								$query = $this->insertdatasql("name,lastname,email,Tel,Workplace,usernamelogin,passlogin,projaecttype,usertype","`usersystem`",$input);
								
								if(!$query){
									
									//print $input;
											echo "Record already exist.<br>";
									
									}else{
										$this->sendmail($mails);
										// echo "<meta http-equiv='refresh' content='0;URL=user.php'>";		
										
										}
							}else{
								
								$_SESSION['code_error'] = "Usernames นี้ถูกใช้เป็นแล้วน";

							}
			
					}else{
							
						$_SESSION['code_error'] = "กรุณากรอ Password ให้ตรงกัน";
					}

			}else{
				
				$_SESSION['code_error'] = "กรุณากรอ ข้อมูลให้ครบ";
				//session_register("code_error");
				//echo "<meta http-equiv='refresh' content='0;URL=adduser.php'>";
				
			}
		
		}

	
}

?>